/*
 * ImageWindow.fx
 *
 * Created on Apr 15, 2010, 3:27:18 PM
 */

package fxgreader;
import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import fxgreader.components.CloseIcon;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.Group;
import javafx.scene.Cursor;

/**
 * @author perkintang
 */

public class ImageWindow extends CustomNode{
public var imageURL : String = "" on replace {
        image  = Image{
                    smooth: false
                    preserveRatio : true;
                    url : imageURL
                 };
};
public var image : Image = Image{
                    smooth: false
                    preserveRatio : true;
                    url : imageURL
                    backgroundLoading:true
                 };
public var width : Number = bind image.width + 50;
public var height : Number = bind image.height + 50;
public var onClose : function();
def closeButton : CloseIcon = CloseIcon{
                                    blocksMouse : true;
                                    onClick: function(){
                                        onClose();
                                        imageURL = "";
                                    }
                                    translateX : width-10-20
                                    translateY : 10
                                };
def background = Rectangle {
                blocksMouse : true;
                cursor : Cursor.HAND;
                stroke : Color.WHITE
                width:  bind width  height: bind height
                arcWidth: 20  arcHeight: 20
                opacity:0.3
                onMouseClicked:function(event:MouseEvent):Void{
                    onClose();
                    imageURL = "";
                }
         };
def view : ImageView= ImageView {
        cursor : Cursor.HAND;
        blocksMouse : true;
        translateX : 25
        translateY : 25
        image: bind image
        onMouseEntered:function(event:MouseEvent):Void{
        }
        onMouseExited:function(event:MouseEvent):Void{
        }
        onMouseClicked:function(event:MouseEvent):Void{
            onClose();
            imageURL = "";
        }
};
def group : Group = Group{
    content : [background,view]
};
override protected function create () : Node {
    group
}
}
